/*
 *  Copyright 2010 mazhao.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package shopping.customer.onthefly;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import shopping.commons.BaseAction;
import shopping.model.Order;
import shopping.model.OrderItem;

/**
 * @author mazhao
 */
@org.apache.struts2.convention.annotation.Namespace("/customer/onthefly")
@org.apache.struts2.convention.annotation.ParentPackage(value = "shopping-json-default")
@org.apache.struts2.convention.annotation.InterceptorRefs({
        @org.apache.struts2.convention.annotation.InterceptorRef("jsonValidationWorkflowStack"),
        @org.apache.struts2.convention.annotation.InterceptorRef("defaultStack")
})
public class OrderItemAction extends BaseAction {
    // ===========================================
    // Business Data and Getter Methods.
    // ===========================================

    private List<OrderItem> orderItems;

    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    private int orderId;

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    // ===========================================
    // Business Action Methods.
    // ===========================================

    @Action(value = "/customer/onthefly/listorderitems",
            results = {
                    @Result(name = "success", type = "json")
            })
    public String listOrderItems() {
        log.debug("enter customer/onthefly/listorderitems action. ");
        log.debug("order id is " + orderId);
        Order order = new Order();
        order.setId(orderId);
        this.orderItems = order.getOrderItems();

        if (log.isDebugEnabled()) {
            for (OrderItem item : orderItems) {
                log.debug(item);
            }
        }

        return SUCCESS;
    }
}
